﻿Imports System.IO
Imports System.Xml.Serialization

<Serializable()> _
Public Class ConfigurationManager
    Private serializer As System.Xml.Serialization.XmlSerializer
    Private lstConfigurations As List(Of IPConfiguration)
    Public Sub New()
        lstConfigurations = New List(Of IPConfiguration)

    End Sub

    Public Function getConfigurations() As List(Of IPConfiguration)
        Return lstConfigurations
    End Function
    Public Sub AddConfiguration(ByVal pIPConfiguration As IPConfiguration)
        lstConfigurations.Add(pIPConfiguration)
    End Sub
    Public Sub SetList(ByVal pConfigurations As List(Of IPConfiguration))
        lstConfigurations = pConfigurations
    End Sub
    Public Sub SaveToXML(ByVal pPath As FileInfo)
        If Not pPath.Directory.Exists Then
            pPath.Directory.Create()
        End If
        Using objDatei As New System.IO.FileStream(pPath.FullName, IO.FileMode.Create)
         serializer = New XmlSerializer(lstConfigurations.GetType)
            serializer.Serialize(objDatei, lstConfigurations)
            serializer = Nothing
            objDatei.Close()
        End Using
        
    End Sub
    Public Sub LoadFromXML(ByVal pPath As FileInfo)
        lstConfigurations = New List(Of IPConfiguration)
        If pPath.Exists Then
            Using objDatei As New FileStream(pPath.FullName, FileMode.Open)
                serializer = New XmlSerializer(lstConfigurations.GetType)
                lstConfigurations = serializer.Deserialize(objDatei)
                serializer = Nothing
                objDatei.Close()
            End Using

        End If

    End Sub

End Class
